<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>产品规格表</title>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body>

<table id="ct" lay-filter="ct"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
    </div>
</script>

<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="delete">删除</a>
</script>
</body>
<script>
    //加载模块
    layui.use(['layer', 'table', 'element','dropdown','form'],function() {
        var layer = layui.layer //弹框
            ,table = layui.table //表格
            , element = layui.element //元素操作
            ,dropdown = layui.dropdown //下拉菜单
            ,$ = layui.$
            ,form = layui.form;
        //载入数据
        table.render({
            elem: '#ct'
            , height: 800
            , url: '/ct/query' //数据接口
            , toolbar: '#toolbarDemo'
            , title: '产品规格表'
            , page: true //开启分页
            , even: true
            // , limit: 10
            , cols: [[ //表头
                {
                    type: 'checkbox',
                    fixed: 'left',
                    width: '3%'
                }
                ,{
                    field: 'id', title: '编号', width: '7%', sort: true, fixed: 'left', templet: function (res) {
                        return res.ct.id;
                    }
                }
                , {
                    field: 'type', title: '速别', width: '10%', sort: true, templet: function (res) {
                        return res.ct.type;
                    }
                }
                , {
                    field: 'name', title: '规格名称', width: '20%', templet: function (res) {
                        return res.ps.name;
                    }
                }
                , {
                    field: 'color', title: '颜色', width: '10%', templet: function (res) {
                        return res.ct.color;
                    }
                }
                , {
                    field: 'maxSection', title: '最大节数', width: '15%', sort: true, templet: function (res) {
                        return res.ct.maxSection;
                    }
                }
                , {
                    field: 'minSection', title: '最小节数', width: '15%', sort: true, templet: function (res) {
                        return res.ct.minSection;
                    }
                }
                , {
                    field: 'method', title: '结尾方式', width: '10%', templet: function (res) {
                        return res.ct.method == true ? "是" : "否";
                    }
                }
                , {field: '', title: '操作', width: '10%', toolbar: '#bar'}
            ]]
            ,parseData:function (res) {
                return {
                    "count":res.count,
                    "msg":res.msg,
                    "data":res.data,
                    "code":res.code
                }
            }
            ,request:{
                pageName: "start_code",
                limitName: "page_size"
            }
        });
        //
        table.on('tool(ct)', function(obj){
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var id = obj.data.ct.id;
            objdata = id;
            if(layEvent === 'detail'){
                toJumpGet($('.layui-body'),"/pages/ct/ctUnique.html");
            } else if(layEvent === 'delete'){
                $.post(
                    "/ct/fakeDelete", {
                        id: id
                    },function (res) {
                        var code = res.code;
                        if (code == 0){
                            layer.alert(res.msg);
                            toJumpGet($('.layui-body'),"/pages/ct/ctList.html");
                        }else {
                            layer.alert(res.msg);
                        }
                    }
                );
            }
        });
    });
</script>
</html>